package jhub;
/*
 * Main.java
 *
 * Created on 29 de Junho de 2005, 14:37
 */

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Properties;
import jhub.dao.DAOFactory;
import org.apache.log4j.BasicConfigurator;
/**
 *
 * @author  botelhodaniel
 */
public class Main {
    
    
    
    public static void main(String[] args) throws ClassNotFoundException, SQLException, ParseException {
        //BasicConfigurator.configure();
        Settings settings = null;
        try {
            settings = new Settings("settings.xml");
        } catch (IOException e) {
            e.printStackTrace();
            try {
                Settings.makeDefault();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            try {
                settings = new Settings("settings.xml");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
        int hub_id = -1;
        
        if(args.length > 0 && args[0].equals("test")){
            DAOFactory.DB_PASS = settings.getProperty(Settings.PropertyKey.test_db_pass);
            DAOFactory.DB_URL = settings.getProperty(Settings.PropertyKey.test_db_url);
            DAOFactory.DB_USER = settings.getProperty(Settings.PropertyKey.test_db_user);
            
            hub_id = Integer.parseInt(settings.getProperty(Settings.PropertyKey.test_hub_id));
        }else{
            
            DAOFactory.DB_PASS = settings.getProperty(Settings.PropertyKey.db_pass);
            DAOFactory.DB_URL = settings.getProperty(Settings.PropertyKey.db_url);
            DAOFactory.DB_USER = settings.getProperty(Settings.PropertyKey.db_user);
            
            hub_id = Integer.parseInt(settings.getProperty(Settings.PropertyKey.hub_id));
        }
        
        System.out.println(System.getProperty("user.dir"));
        
        new HubSession(DAOFactory.getHubDAO().getHubByID(hub_id)).startSession();
    }
}
